<template>
	<uni-list>
		<uni-list-item link @click="chooseImg">
			<template #header>
				<view class="h-20n flex flex-a-c">
					<text>头像</text>
				</view>
			</template>
			<template #footer>
				<view class="flex flex-a-c">
					<image class="round-50-p w-20n h-20n" :src="userInfo?.avatar" mode="aspectFill"></image>
				</view>
			</template>
		</uni-list-item>
		<uni-list-item link @click="toNickname">
			<template #header>
				<view class="h-20n flex flex-a-c">
					<text>{{ userInfo?.nickname }}</text>
				</view>
			</template>
			<template #footer>
				<view class="h-20n flex flex-a-c text999">
					<text>点击修改</text>
				</view>
			</template>
		</uni-list-item>
		<!-- <uni-list-item title="手机号" link @click="onClick($event,1)">
			<template #footer>
				<view class="w-20n h-20n text-align-right">
					
				</view>
			</template>
		</uni-list-item> -->
	</uni-list>
</template>

<script setup>
	import {
		myInfo,
		uploadImg
	} from '@/network/api.js'
	import {
		baseKey,
		baseStr
	} from '@/network/http.js'
	const userInfo = ref()
	// 获取我的详情
	const getMyInfo = async () => {
		const res = await myInfo()
		if (res.status === 200) {
			userInfo.value = res.data
		} else {
			uni.showToast({
				title: res.msg,
				icon: 'none'
			})
		}
	}

	onShow(() => {
		getMyInfo()
	})
	const chooseImg = () => {
		uni.chooseImage({
			count: 1,
			sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
			crop: {
				width: 200,
				height: 200,
			},
			sourceType: ['album'], //从相册选择
			success: (res) => {
				uni.showLoading({
					title: '图片上传中',
				});
				uni.uploadFile({
					url: uploadImg(),
					filePath: res.tempFilePaths[0],
					name: 'file',
					formData: {
						'filename': 'pics',
					},
					header: {
						// #ifdef MP
						"Content-Type": "multipart/form-data",
						// #endif
						[baseKey]: baseStr + uni.getStorageSync('token'),
					},
					success: (e) => {
						console.log(e)
					},
					complete() {
						uni.hideLoading()
					}
				})
			}
		})
	}

	const toNickname = () => {
		uni.navigateTo({
			url: '/pages/mine/nickname'
		})
	}
</script>

<style>

</style>